NODE ANALYSIS
# Check graph edges and vertices
V(hero_g2) #contents in vertices
## + 27/27 vertices, named, from d083a1e:
## [1] LEEDS, BETTY BRANT MAXWELL, MORRIS THORSON, DR. WALTER
## [4] SPIDER-MAN/PETER PAR THOMPSON, EUGENE FLA WATSON-PARKER, MARY
## [7] ICEMAN/ROBERT BOBBY OVERRIDE/DR. GREGORY KWAN, TERRY
## [10] URICH, BEN DOLMAN THOR/DR. DONALD BLAK
## [13] TOKKOTS MCCORMICK, BARRY JAMESON, J. JONAH
## [16] PARKER, MAY FAIRMONT, HANNAH ANGEL/WARREN KENNETH
## [19] MANSLAUGHTER GRANT, GLORIA GLORY NORRISS, SISTER BARB
## [22] STAR THIEF II GARGOYLE II/ISAAC CH KUBIK
## [25] CLOUD BEAST/HENRY &HANK& P ANDROMEDA/ANDROMEDA
gorder(hero_g2) # Count number of vertices
## [1] 27
E(hero_g2) #contents in edges
## + 100/100 edges from d083a1e (vertex names):
## [1] LEEDS, BETTY BRANT --OVERRIDE/DR. GREGORY
## [2] LEEDS, BETTY BRANT --ICEMAN/ROBERT BOBBY
## [3] LEEDS, BETTY BRANT --WATSON-PARKER, MARY
## [4] LEEDS, BETTY BRANT --THOMPSON, EUGENE FLA
## [5] LEEDS, BETTY BRANT --SPIDER-MAN/PETER PAR
## [6] LEEDS, BETTY BRANT --THORSON, DR. WALTER
## [7] LEEDS, BETTY BRANT --MAXWELL, MORRIS
## [8] MAXWELL, MORRIS --JAMESON, J. JONAH
## [9] MAXWELL, MORRIS --DOLMAN
## [10] MAXWELL, MORRIS --URICH, BEN
## + ... omitted several edges
gsize(hero_g2)# Count number of edges
## [1] 100
# Measure the size of network
diameter(hero_g2, directed=FALSE, weights=NA) #the length of the longest path between two nodes is 4
## [1] 4
get_diameter(hero_g2, directed=FALSE, weights=NA) # identify the longest path
## + 5/27 vertices, named, from d083a1e:
## [1] THOR/DR. DONALD BLAK SPIDER-MAN/PETER PAR ICEMAN/ROBERT BOBBY
## [4] ANGEL/WARREN KENNETH NORRISS, SISTER BARB
# Plot social networks
plot(hero_g2, layout = layout_with_lgl(hero_g2), vertex.label=NA)

# Compute edge_density
edge_density(hero_g2)
## [1] 0.2849003
# Compute mean_distance of graph
mean_distance(hero_g2, directed = FALSE)
## [1] 2.210826
# Compute clustering coefficient to find the probability that the adjacent vertices of a vertex are connected
transitivity(hero_g2, type = "average")
## [1] 0.870511
# Calculate the degree
hero_deg <- degree(hero_g2, mode = c("all"))
which.max(hero_deg)
## SPIDER-MAN/PETER PAR
## 4
# Top most popular
top<-mean(hero_deg)+ 0.8*sd(hero_deg)
length(hero_deg[hero_deg>top])
## [1] 3
hero_deg[hero_deg>top]
## SPIDER-MAN/PETER PAR ICEMAN/ROBERT BOBBY JAMESON, J. JONAH
## 18 13 17
# Calculate betweenness of each vertex to find the degree of which heroes stand between each other
betw <- betweenness(hero_g2, directed = F)
which.max(betw)
## ANGEL/WARREN KENNETH
## 18
# Betweeness of top most popular heroes
top<-mean(betw)+ 0.9*sd(betw)
length(betw[betw>top])
## [1] 3
betw[betw>top]
## SPIDER-MAN/PETER PAR ICEMAN/ROBERT BOBBY ANGEL/WARREN KENNETH
## 60.67857 153.55357 154.00000
# Identify key nodes using eigenvector centrality to measure the influence of a node in a network
g.ec <- eigen_centrality(hero_g2)
which.max(g.ec$vector)
## SPIDER-MAN/PETER PAR
## 4
# Measure the influence of top most popular heroes
top<-mean(g.ec$vector)+ 1.2*sd(g.ec$vector)
length(g.ec$vector[g.ec$vector>top])
## [1] 2
g.ec$vector[g.ec$vector>top]
## SPIDER-MAN/PETER PAR JAMESON, J. JONAH
## 1.0000000 0.9615964
# Spider Man is the most influence character and has most connections in the network.
# Find who is around Spider Man ?
g_spiderman <- make_ego_graph(hero_g2, diameter(hero_g2), nodes = 'SPIDER-MAN/PETER PAR', mode = c("all"))[[1]]
V(g_spiderman)$color <- ifelse(V(g_spiderman)$name=="SPIDER-MAN/PETER PAR","blue","pink")
plot(g_spiderman, vertex.label=NA)

# Neighbors of Spider Man
unique(neighbors(hero_g2, v=which(V(hero_g2)$name=="SPIDER-MAN/PETER PAR")))
## + 17/27 vertices, named, from d083a1e:
## [1] LEEDS, BETTY BRANT MAXWELL, MORRIS THORSON, DR. WALTER
## [4] THOMPSON, EUGENE FLA WATSON-PARKER, MARY ICEMAN/ROBERT BOBBY
## [7] OVERRIDE/DR. GREGORY KWAN, TERRY URICH, BEN
## [10] DOLMAN THOR/DR. DONALD BLAK TOKKOTS
## [13] MCCORMICK, BARRY JAMESON, J. JONAH PARKER, MAY
## [16] FAIRMONT, HANNAH GRANT, GLORIA GLORY
# Warren Kenneth is having the most control over the network
# Find who is around Warren Kenneth ?
g_warren <- make_ego_graph(hero_g2, diameter(hero_g2), nodes = "ANGEL/WARREN KENNETH", mode = c("all"))[[1]]
V(g_warren)$color <- ifelse(V(g_warren)$name=="ANGEL/WARREN KENNETH","blue","pink")
plot(g_warren, vertex.label=NA)

# Neighbors of Warren Kenneth
unique(neighbors(hero_g2, v=which(V(hero_g2)$name=="ANGEL/WARREN KENNETH")))
## + 9/27 vertices, named, from d083a1e:
## [1] ICEMAN/ROBERT BOBBY MANSLAUGHTER NORRISS, SISTER BARB
## [4] STAR THIEF II GARGOYLE II/ISAAC CH KUBIK
## [7] CLOUD BEAST/HENRY &HANK& P ANDROMEDA/ANDROMEDA
# Use centrality to summarize which Marvel characteristics have more connections than others
hero_g_eigen_centrality_people=as.data.frame(eigen_centrality(hero_g2)$vector)
hero_g_eigen_centrality_people$hero=rownames(hero_g_eigen_centrality_people)
rownames(hero_g_eigen_centrality_people)<-1:nrow(hero_g_eigen_centrality_people)
colnames(hero_g_eigen_centrality_people)<-c("eigen_centrality_score","hero")
hero_g_eigen_centrality_people_20<-hero_g_eigen_centrality_people[1:20,] #identify which Marvel characteristics are more important than others in selected first 20 characters
# According to eigen centrality score, Spider Man is the most influence node within this network
herro_connection <- ggplot(hero_g_eigen_centrality_people_20, aes(x=hero,y=eigen_centrality_score))
herro_connection + geom_bar(stat="identity", fill = "#000000")+coord_flip()

SUBGROUP ANALYSIS
# Identify clusters or communities of nodes in hero network
components(hero_g2) #this network has 1 components
## $membership
## LEEDS, BETTY BRANT MAXWELL, MORRIS THORSON, DR. WALTER
## 1 1 1
## SPIDER-MAN/PETER PAR THOMPSON, EUGENE FLA WATSON-PARKER, MARY
## 1 1 1
## ICEMAN/ROBERT BOBBY OVERRIDE/DR. GREGORY KWAN, TERRY
## 1 1 1
## URICH, BEN DOLMAN THOR/DR. DONALD BLAK
## 1 1 1
## TOKKOTS MCCORMICK, BARRY JAMESON, J. JONAH
## 1 1 1
## PARKER, MAY FAIRMONT, HANNAH ANGEL/WARREN KENNETH
## 1 1 1
## MANSLAUGHTER GRANT, GLORIA GLORY NORRISS, SISTER BARB
## 1 1 1
## STAR THIEF II GARGOYLE II/ISAAC CH KUBIK
## 1 1 1
## CLOUD BEAST/HENRY &HANK& P ANDROMEDA/ANDROMEDA
## 1 1 1
##
## $csize
## [1] 27
##
## $no
## [1] 1
hero_subgroup2 <- decompose(hero_g2)[[1]]
par(mar=c(0,0,0,0))
V(hero_subgroup2)$color <- ifelse(V(hero_subgroup2)$name=="ANGEL/WARREN KENNETH","blue","pink")
plot(hero_subgroup2,cex=0.005)

cluster_infomap(hero_subgroup2)
## IGRAPH clustering infomap, groups: 3, mod: 0.34
## + groups:
## $`1`
## [1] "LEEDS, BETTY BRANT" "MAXWELL, MORRIS" "THORSON, DR. WALTER"
## [4] "SPIDER-MAN/PETER PAR" "THOMPSON, EUGENE FLA" "WATSON-PARKER, MARY "
## [7] "ICEMAN/ROBERT BOBBY " "OVERRIDE/DR. GREGORY" "KWAN, TERRY"
## [10] "URICH, BEN" "DOLMAN"
##
## $`2`
## [1] "ANGEL/WARREN KENNETH" "MANSLAUGHTER" "NORRISS, SISTER BARB"
## [4] "STAR THIEF II" "GARGOYLE II/ISAAC CH" "KUBIK"
## [7] "CLOUD" "BEAST/HENRY &HANK& P" "ANDROMEDA/ANDROMEDA "
## + ... omitted several groups/vertices
# Map the flow of information in hero network, and the different clusters in which information may get remain for longer periods
comm <- cluster_infomap(hero_subgroup2)
modularity(comm) # modularity score
## [1] 0.33665
# Plot the resulting communities
par(mar=c(0,0,0,0))
plot(comm, hero_subgroup2,cex=0.0005)
